#!/bin/bash

############ script usage
function usage {
	echo -e "\n*****************************************"
	echo "* usage:"
	echo "* clean          : $0 clean"
	# echo "* build image    : $0 build"
	echo "* run            : $0 start"
	echo -e "*******************************************\n"
}


##################### const definition
c_name=mysql_v1   # container name
#####################
# run
function run {
	mkdir -p /tmp/mysql

	docker run -ti \
	--name $c_name \
	-v /tmp/mysql:/var/lib/mysql \
	-v $PWD/conf:/etc/mysql/conf.d \
	-v $PWD/init:/docker-entrypoint-initdb.d \
	-e MYSQL_ROOT_PASSWORD=123456 \
	-p 3306:3306 \
	mysql:5.7 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
}


########### main logic

############ args check
if [ $# -eq 0 ];then
	usage
	exit 1;
fi

############
action=$1
echo "action  : $action"

if [ "$action" == "start" ]; then
	run
elif [ "$action" == "clean" ]; then
	docker rm -f $c_name 2> /dev/null
elif [ "$action" == "build" ]; then
	docker build -t $c_name .
else
	usage
	exit 1
fi


